package cn.ysym.tcsy;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;

import cn.ysym.dao.SettingDao;
import cn.ysym.model.Setting;
import cn.ysym.util.HttpUtil;

public class SettingActivity extends AppCompatActivity {

    private EditText edURL;
    private SettingDao settingDao;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);

        Button bSave = findViewById(R.id.bSave);
        Button bBack = findViewById(R.id.bBack);
        edURL = findViewById(R.id.edURL);
        settingDao = new SettingDao(this);

        //键盘挤压布局
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

        //url初始化
        edURL.setText(settingDao.query("urlPath").getSettingValue());


        //保存
        bSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Setting url = new Setting();
                url.setSettingType("urlPath");
                url.setSettingValue(edURL.getText().toString());
                settingDao.update(url);
                HttpUtil.SERVICE_URL_BASE = url.getSettingValue();
                finish();
            }
        });

        //返回
        bBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });


    }
}
